package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.WaContactUnit;
import com.ruoyi.system.mapper.WaContactUnitMapper;
import com.ruoyi.system.service.WaContactUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WaContactUnitServiceImpl implements WaContactUnitService {
    @Autowired
    private WaContactUnitMapper waContactUnitMapper;
    @Override
    public int add(WaContactUnit waContactUnit) {
           return waContactUnitMapper.add(waContactUnit);
    }


    @Override
    public int deleteUnitById(long unitId) {
        return waContactUnitMapper.deleteUnitById(unitId);
    }

    @Override
    public int updateUnit(WaContactUnit contactUnit) {
        return waContactUnitMapper.updateUnit(contactUnit);
    }

    @Override
    public List<WaContactUnit> listUnitsWithUsers(String unitName) {
        // 预处理：去除首尾空格，避免空字符串导致的无效查询
        String searchKey = (unitName != null) ? unitName.trim() : null;
        // 调用Mapper查询（searchKey为null时查询所有）
        return waContactUnitMapper.selectUnitWithUsers(searchKey);
    }


}
